home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / libkmid / midimapper.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-10-08  |  5.9 KB  |  211 lines

  1. /*  midimapper.h  - The midi mapper object
  2.     This file is part of LibKMid 0.9.5
  3.     Copyright (C) 1997,98,99,2000  Antonio Larrosa Jimenez
  4.     LibKMid's homepage : http://www.arrakis.es/~rlarrosa/libkmid.html
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.  
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU Library General Public License
  17.     along with this library; see the file COPYING.LIB.  If not, write to
  18.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19.     Boston, MA 02110-1301, USA.
  20.  
  21.     Send comments and bug fixes to Antonio Larrosa <larrosa@kde.org>
  22.  
  23. ***************************************************************************/
  24. #ifndef _MIDIMAPPER_H
  25. #define _MIDIMAPPER_H
  26.  
  27. #include <stdio.h>
  28. #include <libkmid/dattypes.h>
  29. #include <kdelibs_export.h>
  30.  
  31. #define KM_NAME_SIZE 30
  32.  
  33. /**
  34.  * A Midi Mapper class which defines the way MIDI events are translated
  35.  * (or "mapped") to different ones. This way, when two MIDI devices "talk"
  36.  * in a somehow different way, they can still communicate.
  37.  *
  38.  * When the user has an external keyboard that is not compatible with the
  39.  * General Midi standard, he can use a MIDI mapper file to play files
  40.  * as if the synthesizer was GM compatible.
  41.  *
  42.  * Please see the KMid documentation 
  43.  * ( http://www.arrakis.es/~rlarrosa/kmid.html ) for information on the
  44.  * format of a MIDI mapper definition file, and how they work.
  45.  * 
  46.  * I created this class because I had one of those non-GM keyboards, 
  47.  * so it can do everything I needed it to do for my keyboard to work
  48.  * exactly as a GM synth, and a few more things. Currently, it's the most
  49.  * featured MIDI mapper available.
  50.  *
  51.  * The usage of this class is quite simple, just create an object with
  52.  * a correct filename in the constructor and then use this object as
  53.  * parameter for DeviceManager::setMidiMap().
  54.  *
  55.  * @short Midi Mapper
  56.  * @version 0.9.5 17/01/2000
  57.  * @author Antonio Larrosa Jimenez <larrosa@kde.org>  
  58.  */
  59. class KMID_EXPORT MidiMapper
  60. {
  61.   private:
  62.     class MidiMapperPrivate;
  63.     MidiMapperPrivate *d;
  64.  
  65.     /**
  66.      * @internal
  67.      * Internal definition for Keymaps
  68.      */
  69.     struct Keymap
  70.     {
  71.       char name[KM_NAME_SIZE];
  72.       uchar key[128];
  73.       struct Keymap *next;
  74.     };
  75.  
  76.     int    _ok;
  77.  
  78.     uchar    channelmap[16]; 
  79.     /**
  80.      * @internal
  81.      * It's a pointer to the Keymap to use for a channel
  82.      * This variable is used to get faster a given Keymap
  83.      * The index is the real channel (after mapping it)
  84.      */
  85.     Keymap *channelKeymap[16]; 
  86.  
  87.     /**
  88.      * @internal
  89.      * It's -1 if the channel doesn't have a forced patch,
  90.      * else indicates the patch to force in the channel.
  91.      */
  92.     int    channelPatchForced[16]; 
  93.  
  94.     uchar    patchmap[128];
  95.  
  96.     /**
  97.      * @internal
  98.      * Same as channelKeymap
  99.      */ 
  100.     Keymap *patchKeymap[128];
  101.  
  102.     /**
  103.      * @internal
  104.      * Real linked list of keymaps used around the class.
  105.      */
  106.     Keymap *keymaps; 
  107.  
  108.     /**
  109.      * @internal
  110.      * Stores the name of the file from which the map was loaded
  111.      */
  112.     char *_filename; 
  113.  
  114.     /**
  115.      * @internal
  116.      * Simulate expression events with volume events
  117.      */
  118.     int mapExpressionToVolumeEvents; 
  119.  
  120.     /**
  121.      * @internal
  122.      * Map or not the Pitch Bender using pitchBenderRatio()
  123.      */
  124.     int mapPitchBender;
  125.  
  126.     /**
  127.      * @internal
  128.      * Indicates the ratio between the standard and the synthesizer's pitch
  129.      * bender engine. The number sent to the synth is multiplied by this
  130.      * and dividied by 4096. Thus if PitchBenderRatio is 4096, the synth's
  131.      * pitch bender works as the standard one
  132.      */
  133.     int pitchBenderRatio; 
  134.  
  135.     void getValue(char *s,char *v);
  136.     void removeSpaces(char *s);
  137.     int  countWords(char *s);
  138.     void getWord(char *t,char *s,int w); 
  139.     // get from s the word in position  w and store it in t
  140.  
  141.     void deallocateMaps(void);
  142.     Keymap *createKeymap(char *name,uchar use_same_note=0,uchar note=0);
  143.     void readPatchmap(FILE *fh);
  144.     void readKeymap(FILE *fh,char *first_line);
  145.     void readChannelmap(FILE *fh);
  146.     void readOptions(FILE *fh);
  147.  
  148.     void addKeymap(Keymap *newkm);
  149.     Keymap *keymap(char *n);
  150.  
  151.   public:
  152.     /**
  153.      * Constructor. Loads a MIDI Mapper definition from a file.
  154.      * @see filename()
  155.      */
  156.     MidiMapper(const char *name);
  157.  
  158.     /**
  159.      * Destructor.
  160.      */
  161.     ~MidiMapper();
  162.  
  163.     /**
  164.      * Loads a MIDI Mapper definition file (you don't need to use this if you
  165.      * used a correct filename in constructor). 
  166.      */
  167.     void loadFile(const char *name);    
  168.  
  169.     /**
  170.      * Returns the status of the object.
  171.      */
  172.     int  ok(void) { return _ok; }
  173.  
  174.     /** 
  175.      * Returns the channel which chn should be mapped to.
  176.      */ 
  177.     uchar channel(uchar chn) { return channelmap[chn];}
  178.  
  179.     /** 
  180.      * Returns the patch which pgm used on channel chn should be mapped to.
  181.      */ 
  182.     uchar patch(uchar chn,uchar pgm);
  183.  
  184.     /** 
  185.      * Returns the key that key note playing a pgm patch on channel chn should
  186.      * be mapped to.
  187.      */ 
  188.     uchar key(uchar chn,uchar pgm, uchar note);
  189.  
  190.     /**
  191.      * Returns the value which the pitch bender on channel chn should be
  192.      * mapped to.
  193.      */
  194.     void  pitchBender(uchar chn,uchar &lsb,uchar &msb);
  195.  
  196.     /**
  197.      * Returns the value which a given controller and its value should
  198.      * be mapped to when played on channel chn.
  199.      */ 
  200.     void  controller(uchar chn,uchar &ctl,uchar &v);
  201.  
  202.     /**
  203.      * Returns the path and name of the file which the object loaded the
  204.      * mapper from.
  205.      */
  206.     const char *filename(void);
  207.  
  208. };
  209.  
  210. #endif
  211.